cd "4_IAT"

log using "./log files/figure4.txt", replace

use "./data/iat_predictions.dta", replace

set scheme s1color

label var pred_2019 "2019"
label var pred_2020 "2020"

format week %td

/* Figure 4 */
twoway (scatter pred_2019 week if week <td(25may2020) & df == "full", mcolor(gs13) msize(small) msymbol(S))(scatter pred_2019 week if week>=td(25may2020) & df == "full", mcolor(gs13) msize(small) msymbol(S)) ///
(scatter pred_2020 week if week <td(25may2020) & df == "full", msize(small) mcolor(gs5))(scatter pred_2020 week if week>=td(25may2020) & df == "full", msize(small) mcolor(gs5)) ///
(lowess pred_2019 week if week <td(25may2020) & df == "full", lwidth(thick) lcolor(gs13) msymbol(S))(lowess pred_2019 week if week>=td(25may2020) & df == "full", lcolor(gs13) lwidth(thick)) ///
(lowess pred_2020 week if week <td(25may2020) & df == "full", lwidth(thick) lpattern(dash) lcolor(gs5))(lowess pred_2020 week if week>=td(25may2020) & df == "full", lcolor(gs5) lwidth(thick) lpattern(dash)), ///
ylabel(.2(.1).5,nogrid) tlabel(01jan2020 01feb2020 01march2020 01april2020 01may2020 01june2020 01july2020 01august2020 01september2020 01october2020 01november2020 01dec2020, format(%tdMon) alternate) ///
yscale(range(.2, .5)) xtitle(" ") ytitle("Predicted D-Scores") xline(22056, lcolor(red)) ///
title("Full Sample") legend(order(1 3)) name("fullSamp", replace)

twoway (scatter pred_2019 week if week <td(25may2020) & df == "white", mcolor(gs13) msize(small) msymbol(S))(scatter pred_2019 week if week>=td(25may2020) & df == "white", mcolor(gs13) msize(small) msymbol(S)) ///
(scatter pred_2020 week if week <td(25may2020) & df == "white", msize(small) mcolor(gs5))(scatter pred_2020 week if week>=td(25may2020) & df == "white", msize(small) mcolor(gs5)) ///
(lowess pred_2019 week if week <td(25may2020) & df == "white", lwidth(thick) lcolor(gs13) msymbol(S))(lowess pred_2019 week if week>=td(25may2020) & df == "white", lcolor(gs13) lwidth(thick)) ///
(lowess pred_2020 week if week <td(25may2020) & df == "white", lwidth(thick) lpattern(dash) lcolor(gs5))(lowess pred_2020 week if week>=td(25may2020) & df == "white", lcolor(gs5) lwidth(thick) lpattern(dash)), ///
ylabel(.2(.1).5,nogrid) tlabel(01jan2020 01feb2020 01march2020 01april2020 01may2020 01june2020 01july2020 01august2020 01september2020 01october2020 01november2020 01dec2020, format(%tdMon) alternate) ///
yscale(range(.2, .5)) xtitle(" ") ytitle("Predicted D-Scores") xline(22056, lcolor(red)) ///
title("Among Whites") legend(order(1 3)) name("whiteSamp", replace)

twoway (scatter pred_2019 week if week <td(25may2020) & df == "black", mcolor(gs13) msize(small) msymbol(S))(scatter pred_2019 week if week>=td(25may2020) & df == "black", mcolor(gs13) msize(small) msymbol(S)) ///
(scatter pred_2020 week if week <td(25may2020) & df == "black", msize(small) mcolor(gs5))(scatter pred_2020 week if week>=td(25may2020) & df == "black", msize(small) mcolor(gs5)) ///
(lowess pred_2019 week if week <td(25may2020) & df == "black", lwidth(thick) lcolor(gs13) msymbol(S))(lowess pred_2019 week if week>=td(25may2020) & df == "black", lcolor(gs13) lwidth(thick)) ///
(lowess pred_2020 week if week <td(25may2020) & df == "black", lwidth(thick) lpattern(dash) lcolor(gs5))(lowess pred_2020 week if week>=td(25may2020) & df == "black", lcolor(gs5) lwidth(thick) lpattern(dash)), ///
ylabel(-.3(.1)0,nogrid) tlabel(01jan2020 01feb2020 01march2020 01april2020 01may2020 01june2020 01july2020 01august2020 01september2020 01october2020 01november2020 01dec2020, format(%tdMon) alternate) ///
yscale(range(-.3, 0)) xtitle(" ") ytitle("Predicted D-Scores") xline(22056, lcolor(red)) ///
title("Among Blacks") legend(order(1 3)) name("blackSamp", replace)

twoway (scatter pred_2019 week if week <td(25may2020) & df == "conservative", mcolor(gs13) msize(small) msymbol(S))(scatter pred_2019 week if week>=td(25may2020) & df == "conservative", mcolor(gs13) msize(small) msymbol(S)) ///
(scatter pred_2020 week if week <td(25may2020) & df == "conservative", msize(small) mcolor(gs5))(scatter pred_2020 week if week>=td(25may2020) & df == "conservative", msize(small) mcolor(gs5)) ///
(lowess pred_2019 week if week <td(25may2020) & df == "conservative", lwidth(thick) lcolor(gs13) msymbol(S))(lowess pred_2019 week if week>=td(25may2020) & df == "conservative", lcolor(gs13) lwidth(thick)) ///
(lowess pred_2020 week if week <td(25may2020) & df == "conservative", lwidth(thick) lpattern(dash) lcolor(gs5))(lowess pred_2020 week if week>=td(25may2020) & df == "conservative", lcolor(gs5) lwidth(thick) lpattern(dash)), ///
ylabel(.2(.1).5,nogrid) tlabel(01jan2020 01feb2020 01march2020 01april2020 01may2020 01june2020 01july2020 01august2020 01september2020 01october2020 01november2020 01dec2020, format(%tdMon) alternate) ///
yscale(range(.2, .5)) xtitle(" ") ytitle("Predicted D-Scores") xline(22056, lcolor(red)) ///
title("Among White Conservatives") legend(order(1 3)) name("conSamp", replace)

twoway (scatter pred_2019 week if week <td(25may2020) & df == "moderate", mcolor(gs13) msize(small) msymbol(S))(scatter pred_2019 week if week>=td(25may2020) & df == "moderate", mcolor(gs13) msize(small) msymbol(S)) ///
(scatter pred_2020 week if week <td(25may2020) & df == "moderate", msize(small) mcolor(gs5))(scatter pred_2020 week if week>=td(25may2020) & df == "moderate", msize(small) mcolor(gs5)) ///
(lowess pred_2019 week if week <td(25may2020) & df == "moderate", lwidth(thick) lcolor(gs13) msymbol(S))(lowess pred_2019 week if week>=td(25may2020) & df == "moderate", lcolor(gs13) lwidth(thick)) ///
(lowess pred_2020 week if week <td(25may2020) & df == "moderate", lwidth(thick) lpattern(dash) lcolor(gs5))(lowess pred_2020 week if week>=td(25may2020) & df == "moderate", lcolor(gs5) lwidth(thick) lpattern(dash)), ///
ylabel(.2(.1).5,nogrid) tlabel(01jan2020 01feb2020 01march2020 01april2020 01may2020 01june2020 01july2020 01august2020 01september2020 01october2020 01november2020 01dec2020, format(%tdMon) alternate) ///
yscale(range(.2, .5)) xtitle(" ") ytitle("Predicted D-Scores") xline(22056, lcolor(red)) ///
title("Among White Neutrals") legend(order(1 3)) name("modSamp", replace)

twoway (scatter pred_2019 week if week <td(25may2020) & df == "liberal", mcolor(gs13) msize(small) msymbol(S))(scatter pred_2019 week if week>=td(25may2020) & df == "liberal", mcolor(gs13) msize(small) msymbol(S)) ///
(scatter pred_2020 week if week <td(25may2020) & df == "liberal", msize(small) mcolor(gs5))(scatter pred_2020 week if week>=td(25may2020) & df == "liberal", msize(small) mcolor(gs5)) ///
(lowess pred_2019 week if week <td(25may2020) & df == "liberal", lwidth(thick) lcolor(gs13) msymbol(S))(lowess pred_2019 week if week>=td(25may2020) & df == "liberal", lcolor(gs13) lwidth(thick)) ///
(lowess pred_2020 week if week <td(25may2020) & df == "liberal", lwidth(thick) lpattern(dash) lcolor(gs5))(lowess pred_2020 week if week>=td(25may2020) & df == "liberal", lcolor(gs5) lwidth(thick) lpattern(dash)), ///
ylabel(.2(.1).5,nogrid) tlabel(01jan2020 01feb2020 01march2020 01april2020 01may2020 01june2020 01july2020 01august2020 01september2020 01october2020 01november2020 01dec2020, format(%tdMon) alternate) ///
yscale(range(.2, .5)) xtitle(" ") ytitle("Predicted D-Scores") xline(22056, lcolor(red)) ///
title("Among White Liberals") legend(order(1 3)) name("libSamp", replace)

/*combined figure*/
graph combine fullSamp whiteSamp blackSamp conSamp modSamp libSamp, rows(2) note("Note: Y-axis range for Black respondents is different due to different attitude levels.""Predicted weekly means. Lowess smoothing.")
graph export "./figures/Figure4.pdf", replace

capture log close
